package socket.service;

import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 当客户端和服务端连接后，需要向服务端发送登录请求，也就是消息类型：LOGIN
 * 服务端接收到LOGIN请求后，会将客户端加入到队列中
 * Created by yangluhua on 2017/11/1 0001.
 */
public class NettyChannelMap {
    private static Map<String , SocketChannel> map = new ConcurrentHashMap<>();

    public static void add(String clientId,SocketChannel channel){
        map.put(clientId, channel);
    }

    public static Channel get(String clientId){
        return map.get(clientId);
    }

    public static void remove(SocketChannel channel){
        for (Map.Entry<String,SocketChannel> entry:map.entrySet()){
            if (entry.getValue()==channel){
                map.remove(entry.getKey());
            }
        }
    }
}
